<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col>
        <!-- 查询 -->
        <el-form ref="orderData" :model="orderData" size="small" :inline="true" label-width="98px">
          <el-form-item label="请选择太空舱" prop="capsuleInfoId">
            <el-select ref="selectRoom" clearable v-model="dataRoom.capsuleInfoId" placeholder="请选择太空舱基地">
              <el-option v-for="(item ,index) in spaceRoomList" :key="index" :label="item.label"
                :value="item.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="选择时间">
            <el-date-picker v-model="tiemValue" type="daterange" value-format="yyyy-MM-dd" range-separator="--"
              start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']"
              @change="changeTime">
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmitsear" icon="el-icon-search" size="mini">查询</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <!-- 改价列表 -->
        <el-table v-loading="loading" :data="tableData" ref="tableRef" border style="width: 100%" class="mb20">
          <el-table-column prop="capsuleRoomName" label="房间" align="center" width="160">
          </el-table-column>
          <el-table-column prop="changeBeforeRealPrice" label="改价前价格" align="center" width="110">
            <template slot-scope="scope">
              <div style="color: #e45656;">{{scope.row.changeBeforeRealPrice}}元</div>
            </template>
          </el-table-column>
          <el-table-column prop="changeAfterRealPrice" label="改价后价格" align="center" width="110">
            <template slot-scope="scope">
              <div style="color: #e45656;">{{scope.row.changeAfterRealPrice}}元</div>
            </template>
          </el-table-column>
          <el-table-column prop="otherPayPrice" label="三方支付价格" align="center" width="160">
            <template slot-scope="scope">
              <div style="color: #e45656;">{{scope.row.otherPayPrice}}元</div>
            </template>
          </el-table-column>
          </el-table-column>
          <el-table-column prop="changeReason" label="改价原因" align="center">
          </el-table-column>
          <el-table-column prop="changeSourceType" label="改价来源" align="center" width="100">
            <template slot-scope="scope">
              <div>
                {{scope.row.changeSourceType == 0 ? '美团' : (scope.row.changeSourceType == 1 ? '抖音' : (scope.row.changeSourceType == 2 ? '携程' :'其它'))}}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="changePriceTime" label="改价时间" align="center" width="210">
          </el-table-column>
          <el-table-column prop="approveStatus" label="审批状态" align="center" width="120">
            <template slot-scope="scope">
              <el-button v-if="scope.row.approveStatus == 0" size="mini" type="danger" plain
                @click="onExamine(scope.row.id)">审批中</el-button>
              <el-button v-if="scope.row.approveStatus == 1" size="mini" type="success" :disabled="true"
                plain>已通过</el-button>
              <el-button v-if="scope.row.approveStatus == 2" size="mini" type="warning" :disabled="true"
                plain>已拒绝</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination background align='right' @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :current-page="fromData.pageNum" :page-size="fromData.pageSize" layout="prev, pager, next" :total="total">
        </el-pagination>
      </el-col>
    </el-row>
    <el-dialog title="改价" :visible.sync="refundVisibles" width="44%" :before-close="refundClose">
      <el-form ref="refundForm" :model="refundForm" label-width="120px" :rules="refund_rules">
        <el-row>
          <el-col :span="22">
            <el-form-item label="开始审批" prop="approveStatus">
              <el-select v-model="refundForm.approveStatus" placeholder="请选择状态">
                <el-option label="通过" value="1"></el-option>
                <el-option label="拒绝" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer">
        <el-button @click="refundVisibles = false">取 消</el-button>
        <el-button type="primary" @click="onRefundForm('refundForm')">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import {
    onChangePriceList,
    noApproveChange
  } from "@/api/order/order"
  import {
    capsuleInfoSelects
  } from '@/api/space/spaceRoom'
  export default {
    data() {
      return {
        loading: true,
        tableData: [],
        total: 0,
        orderData: {},
        orderStatus: '',
        orderType: [{
            value: 0,
            label: '下单'
          },
          {
            value: 1,
            label: '已支付'
          },
          {
            value: 2,
            label: '已退款'
          },
          {
            value: 3,
            label: '已取消'
          },
          {
            value: 99,
            label: '全部'
          }
        ],
        tiemValue: '',
        fromData: {
          capsuleInfoId: '',
          createBeginTime: '',
          createEndTime: '',
          pageNum: 1,
          pageSize: 10
        },
        dataRoom: {
          capsuleInfoId: ''
        },
        spaceRoomList: [],
        refundVisibles: false,
        refundForm: {},
        id: '',
        refund_rules: {
          type: [{
            required: true,
            message: '请选择审批状态',
            trigger: 'blur'
          }]
        }
      }
    },
    created() {
      capsuleInfoSelects().then(res => {
        this.spaceRoomList = res.data
      })
      this.onChangePriceList()
    },
    methods: {
      onChangePriceList() {
        this.loading = true
        this.fromData.capsuleInfoId = this.dataRoom.capsuleInfoId
        onChangePriceList(this.fromData).then(res => {
          // console.log('finace-->' , res)
          if (res.code == 200) {
            let data = res.data
            this.tableData = data.rows
            this.total = data.total
            this.loading = false
          }
        })
      },
      handleSizeChange(val) {
        this.fromData.pageNum = val
        this.onChangePriceList()
      },
      handleCurrentChange(val) {
        this.fromData.pageNum = val
        this.onChangePriceList()
      },
      changeTime(e) {
        this.fromData.createBeginTime = this.tiemValue[0]
        this.fromData.createEndTime = this.tiemValue[1]
      },
      onSubmitsear() {
        this.onChangePriceList()
      },
      resetQuery() {
        this.fromData = {
          capsuleInfoId: '',
          createBeginTime: '',
          createEndTime: '',
          orderStatus: 99,
          pageNum: 1,
          pageSize: 10
        }
        this.tiemValue = ''
        this.onChangePriceList()
      },
      onExamine(id) {
        this.id = id
        this.refundVisibles = true
      },
      refundClose() {
        this.refundVisibles = false
      },
      onRefundForm(refundForm) {
        this.$refs[refundForm].validate((valid) => {
          if (valid) {
            this.refundForm.id = this.id
            noApproveChange(this.refundForm).then(res => {
              if (res.code == 200) {
                this.$message({
                  type: 'success',
                  message: res.data
                })
                this.refundVisibles = false
                this.onChangePriceList()
              } else {
                this.$message({
                  type: 'error',
                  message: res.data
                })
              }
            })
          }
        })
      },
    }
  }
</script>

<style lang="scss">

</style>
